package com.ruoyi.movie.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.movie.domain.VideoResource;
import com.ruoyi.movie.service.IVideoResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 视频资源Controller
 *
 * @author ruoyi
 * @date 2025-01-22
 */
@RestController
@RequestMapping("/movie/resource")
public class VideoResourceController extends BaseController {

    @Autowired
    private IVideoResourceService videoResourceService;

    /**
     * 查询视频资源列表
     */
    @PreAuthorize("@ss.hasPermi('movie:resource:list')")
    @GetMapping("/list")
    public TableDataInfo list(VideoResource videoResource) {
        startPage();
        List<VideoResource> list = videoResourceService.selectVideoResourceList(videoResource);
        return getDataTable(list);
    }

    /**
     * 根据视频ID查询资源列表
     */
    @GetMapping("/video/{videoId}")
    public AjaxResult getByVideoId(@PathVariable Long videoId) {
        return AjaxResult.success(videoResourceService.selectVideoResourceByVideoId(videoId));
    }

    /**
     * 导出视频资源列表
     */
    @PreAuthorize("@ss.hasPermi('movie:resource:export')")
    @Log(title = "视频资源", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VideoResource videoResource) {
        List<VideoResource> list = videoResourceService.selectVideoResourceList(videoResource);
        ExcelUtil<VideoResource> util = new ExcelUtil<VideoResource>(VideoResource.class);
        util.exportExcel(response, list, "视频资源数据");
    }

    /**
     * 获取视频资源详细信息
     */
    @PreAuthorize("@ss.hasPermi('movie:resource:query')")
    @GetMapping(value = "/{resourceId}")
    public AjaxResult getInfo(@PathVariable("resourceId") Long resourceId) {
        return AjaxResult.success(videoResourceService.selectVideoResourceById(resourceId));
    }

    /**
     * 新增视频资源
     */
    @PreAuthorize("@ss.hasPermi('movie:resource:add')")
    @Log(title = "视频资源", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VideoResource videoResource) {
        return toAjax(videoResourceService.insertVideoResource(videoResource));
    }

    /**
     * 修改视频资源
     */
    @PreAuthorize("@ss.hasPermi('movie:resource:edit')")
    @Log(title = "视频资源", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VideoResource videoResource) {
        return toAjax(videoResourceService.updateVideoResource(videoResource));
    }

    /**
     * 删除视频资源
     */
    @PreAuthorize("@ss.hasPermi('movie:resource:remove')")
    @Log(title = "视频资源", businessType = BusinessType.DELETE)
    @DeleteMapping("/{resourceIds}")
    public AjaxResult remove(@PathVariable Long[] resourceIds) {
        return toAjax(videoResourceService.deleteVideoResourceByIds(resourceIds));
    }
}